package com.ruoyi.project.qyxy.qua.domain;

import com.ruoyi.project.qyxy.person.domain.ZzPerson;
import com.sun.org.apache.regexp.internal.RE;

import java.util.ArrayList;
import java.util.List;

/**
 * 监理企业计算临时累
 */
public class JlQuaTemp {

    /**
     * 资质
     */
    private QuaInfo quaInfo;

    /**
     * 企业拥有人员
     */
    private JlPersonTemp jlPersonTemp;

    /**
     * 已使用注册造价工程师
     */
    private List<ZzPerson> zjPersonList = new ArrayList<>();

    /**
     * 已使用一级注册建造师
     */
    private List<ZzPerson> jzPersonList = new ArrayList<>();

    /**
     * 已使用一级注册建筑师
     */
    private List<ZzPerson> jzhPersonList = new ArrayList<>();

    /**
     * 已使用一级注册结构工程师
     */
    private List<ZzPerson> jgPersonList = new ArrayList<>();

    /**
     * 已使用注册监理工程师
     */
    private List<ZzPerson> jlPersonList = new ArrayList<>();

    /**
     * 资质等级 甲级
     */
    public static final String RUNK_JIA = "甲级";

    /**
     * 资质等级 乙级
     */
    public static final String RUNK_YI = "乙级";

    /**
     * 资质等级 丙级
     */
    public static final String RUNK_BING = "丙级";

    /**
     * 综合资质
     */
    public static final String RUNK_ZH = "不分等级";

    /**
     * 甲乙级造价工程师数量
     */
    public static final int JY_ZJ_MIN_COUNT = 1;

    /**
     * 甲乙其他工程师数量
     */
    public static final int JY_MIN_SUM_COUNT = 15;

    /**
     * 乙级监理工程师数量
     */
    public static final int BING_JL_COUNT = 5;

    /**
     * 综合资质 监理人数
     */
    public static final int ZH_JL_COUNT = 60;

    /**
     * 综合资质 造价人数
     */
    public static final int ZH_ZJ_COUNT = 5;

    /**
     * 综合资质 其他人数
     */
    public static final int ZH_OTHER_COUNT = 15;

    /**
     * 缺少人数
     */
    public int shortOfCount = 0;

    /**
     * 减分
     */
    public String reduceScore;

    private Boolean isQualified;

    /**
     * 资质是否符合标准
     *
     * @return
     */
    public Boolean isQualified() {
        //如果是符合标准资质不处理
        if(JlPersonTemp.isDo == JlPersonTemp.DO && isQualified){
            return isQualified;
        }
        String quaRank = this.quaInfo.getQuaRank();
        //根据资质等级处理资质
        switch (quaRank) {
            case RUNK_JIA:
                return this.isQualified = doJiaAndYi();
                //甲级
            case RUNK_YI:
                return this.isQualified = doJiaAndYi();
                //乙级
            case RUNK_BING:
                return this.isQualified = doBing();
                //丙级
            case RUNK_ZH:
                //不分等级
                return this.isQualified = doZh();
        }
        return this.isQualified = false;
    }

    /**
     * 资质是否符合标准
     * @return
     */
    public Boolean getQualified(){
        return this.isQualified;
    }

    public void printLog(){
        System.out.println("---------------------------------------------------------------------------------------------");
        System.out.println("资质名称:" + quaInfo.getQuaName()+",类别:"+quaInfo.getQuaType()+",等级:"+quaInfo.getQuaRank());
        System.out.println("\t合格:"+ (JlPersonTemp.isDo ? "不合格" : "合格"));
        String quaRank = this.quaInfo.getQuaRank();
        switch (quaRank) {
            case RUNK_JIA:
                printAll();
                break;
            //甲级
            case RUNK_YI:
                printAll();
                break;
            //乙级
            case RUNK_BING:
                printUseJl();
                break;
            //丙级
            case RUNK_ZH:
                //不分等级
                printAll();
                break;
        }
        if(JlPersonTemp.isDo){
            System.out.println("缺少人数:" + shortOfCount +"人");
        }
    }

    public void printAll(){
        printUseJl();
        printUseJz();
        printUseJzh();
        printUseZj();
        printUseJg();
    }

    public void printUseZj(){
        System.out.println("已使用造价工程师:");
        System.out.print("\t");
        for (ZzPerson zzPerson : zjPersonList) {
            System.out.print(zzPerson.getPname()+"("+zzPerson.getRegType()+")");
        }
        System.out.println();
    }

    public void printUseJz(){
        System.out.println("已使用一级注册建造师:");
        System.out.print("\t");
        for (ZzPerson zzPerson : jzPersonList) {
            System.out.print(zzPerson.getPname()+"("+zzPerson.getRegType()+")");
        }
        System.out.println();
    }


    public void printUseJzh(){
        System.out.println("已使用一级注册建筑师:");
        System.out.print("\t");
        for (ZzPerson zzPerson : jzhPersonList) {
            System.out.print(zzPerson.getPname()+"("+zzPerson.getRegType()+")");
        }
        System.out.println();
    }

    public void printUseJg(){
        System.out.println("已使用一级结构工程师:");
        System.out.print("\t");
        for (ZzPerson zzPerson : jgPersonList) {
            System.out.print(zzPerson.getPname()+"("+zzPerson.getRegType()+")");
        }
        System.out.println();
    }

    public void printUseJl(){
        System.out.println("已使用注册监理工程师:");
        System.out.print("\t");
        for (ZzPerson zzPerson : jlPersonList) {
            System.out.print(zzPerson.getPname()+"("+zzPerson.getRegType()+")");
        }
        System.out.println();
    }

    /**
     * 处理甲乙级资质
     * @return
     */
    public Boolean doJiaAndYi(){
        boolean flag = true;
        //监理工程师
        int jlCount = jlPersonTemp.getJlCount();
        //一级造价工程师
        int zjCount = jlPersonTemp.getZjCount();
        //一级注册建造师
        int jzCount = jlPersonTemp.getJzCount();
        //一级注册建筑师
        int jzhCount = jlPersonTemp.getJzhCount();
        //一级结构工程师
        int jgCount = jlPersonTemp.getJgCount();

        if(jlCount < JlQuaTemp.JY_ZJ_MIN_COUNT){
            flag =  false;
        }

        int sumCount = jlCount + zjCount + jzCount + jzhCount + jgCount;
        if(sumCount < JlQuaTemp.JY_MIN_SUM_COUNT){
            flag =  false;
        }
        shortOfCount = jlPersonTemp.reduce(quaInfo.getQuaRank(),flag,this);
        return flag;
    }


    /**
     * 处理丙级资质
     * @return
     */
    public Boolean doBing(){
        boolean flag = true;
        //监理工程师
        int jlCount = jlPersonTemp.getJlCount();
        if(jlCount < BING_JL_COUNT){
            flag = false;
        }
        shortOfCount = jlPersonTemp.reduce(quaInfo.getQuaRank(),flag,this);
        return flag;
    }

    /**
     * 处理综合资质
     * @return
     */
    public Boolean doZh(){
        boolean flag = true;
        //监理工程师
        int jlCount = jlPersonTemp.getJlCount();
        //一级造价工程师
        int zjCount = jlPersonTemp.getZjCount();
        //一级注册建造师
        int jzCount = jlPersonTemp.getJzCount();
        //一级注册建筑师
        int jzhCount = jlPersonTemp.getJzhCount();
        //一级结构工程师
        int jgCount = jlPersonTemp.getJgCount();
        if(jlCount < ZH_JL_COUNT){
            flag = false;
        }
        if(zjCount < ZH_ZJ_COUNT){
            flag = false;
        }
        if((jzCount + jzhCount + jgCount) < ZH_OTHER_COUNT){
            flag =false;
        }
        shortOfCount = jlPersonTemp.reduce(quaInfo.getQuaRank(),flag,this);
        return flag;
    }


    public String getReduceScore() {
        return reduceScore;
    }

    public void setReduceScore(String reduceScore) {
        this.reduceScore = reduceScore;
    }

    public QuaInfo getQuaInfo() {
        return quaInfo;
    }

    public void setQuaInfo(QuaInfo quaInfo) {
        this.quaInfo = quaInfo;
    }

    public JlPersonTemp getJlPersonTemp() {
        return jlPersonTemp;
    }

    public void setJlPersonTemp(JlPersonTemp jlPersonTemp) {
        this.jlPersonTemp = jlPersonTemp;
    }

    public List<ZzPerson> getZjPersonList() {
        return zjPersonList;
    }

    public void setZjPersonList(List<ZzPerson> zjPersonList) {
        this.zjPersonList = zjPersonList;
    }

    public List<ZzPerson> getJzPersonList() {
        return jzPersonList;
    }

    public void setJzPersonList(List<ZzPerson> jzPersonList) {
        this.jzPersonList = jzPersonList;
    }

    public List<ZzPerson> getJzhPersonList() {
        return jzhPersonList;
    }

    public void setJzhPersonList(List<ZzPerson> jzhPersonList) {
        this.jzhPersonList = jzhPersonList;
    }

    public List<ZzPerson> getJgPersonList() {
        return jgPersonList;
    }

    public void setJgPersonList(List<ZzPerson> jgPersonList) {
        this.jgPersonList = jgPersonList;
    }

    public List<ZzPerson> getJlPersonList() {
        return jlPersonList;
    }

    public void setJlPersonList(List<ZzPerson> jlPersonList) {
        this.jlPersonList = jlPersonList;
    }

    public int getShortOfCount() {
        return shortOfCount;
    }
}
